// import store from 'store'
import { isObject, isArray } from 'lodash'
const store = sessionStorage || window.sessionStorage
const regArr = /^\[(.+)\]$/
const regObj = /^\{(.+)\}$/

const storage = {
  get (k) {
    let v = store.getItem(k)
    return regArr.test(v) || regObj.test(v) ? JSON.parse(v) : v
  },
  set (k, v) {
    // console.log('set:', k, v)
    return store.setItem(k, isObject(v) || isArray(v) ? JSON.stringify(v) : v)
  },
  remove (k) {
    // console.log('remove:', k)
    return store.removeItem(k)
  },
  clearAll () {
    // console.log('clearAll')
    return store.clear()
  }
}

export default storage
